package com.ht.controller;

import com.ht.data.Result;
import com.ht.domain.bo.DoctorBO;
import com.ht.domain.po.TbDoctor;
import com.ht.service.DoctorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("doctorController")
@Api
@RefreshScope //开启自动刷新配置
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 通过手机号获取验证码并存放到redis
     * @param phone
     * @return
     */
    @ApiOperation("输入手机号获取验证码")
    @ApiImplicitParam(name = "phone",value = "手机号",required = true,paramType = "query",dataTypeClass = String.class)
    @PostMapping("getVerify")
    public Result getVerify(@RequestParam("phone") String phone){
        rocketMQTemplate.convertAndSend("phone_topic",phone);
        return Result.OK();
    }

    /**
     * 医生注册
     * @param doctor
     * @param verify
     * @return
     */
    @ApiOperation("医生注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctor",value = "医生实体",required = true,paramType = "body",dataTypeClass = TbDoctor.class),
            @ApiImplicitParam(name = "verify",value = "验证码",required = true,paramType = "query",dataTypeClass = String.class)
    })
    @PostMapping
    public Result doctorRegister(@RequestBody TbDoctor doctor,@RequestParam("verify") String verify){
        DoctorBO doctorBO = new DoctorBO();
        BeanUtils.copyProperties(doctor,doctorBO);
        return doctorService.doctorRegister(doctorBO,verify);
    }
}
